#include <iostream>
#include <vector>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

using namespace cv;
using namespace std;

vector<Mat> imageVector;

void multipleImage(vector<Mat> imgVector, Mat& dst, int imgCols)  //参数为列
{
    const int MAX_PIXEL=300;
    int imgNum = imgVector.size();
    //选择图片最大的一边 将最大的边按比例变为300像素
    Size imgOriSize = imgVector[0].size();
    int imgMaxPixel = max(imgOriSize.height, imgOriSize.width);
    //获取最大像素变为MAX_PIXEL的比例因子
    double prop = imgMaxPixel < MAX_PIXEL ?  (double)imgMaxPixel/MAX_PIXEL : MAX_PIXEL/(double)imgMaxPixel;
    Size imgStdSize(imgOriSize.width * prop, imgOriSize.height * prop); //窗口显示的标准图像的Size

    Mat imgStd; //标准图片
    Point2i location(0, 0); //坐标点(从0,0开始)
    //构建窗口大小 通道与imageVector[0]的通道一样
    Mat imgWindow(imgStdSize.height*((imgNum-1)/imgCols + 1), imgStdSize.width*imgCols, imgVector[0].type());
    for (int i=0; i<imgNum; i++)
    {
        location.x = (i%imgCols)*imgStdSize.width;
        location.y = (i/imgCols)*imgStdSize.height;
        resize(imgVector[i], imgStd, imgStdSize, prop, prop, INTER_LINEAR); //设置为标准大小
        imgStd.copyTo( imgWindow( Rect(location, imgStdSize) ) );
    }
    dst = imgWindow;
}

void ManyImages(vector<Mat> Images, Mat& dst, int imgRows)  //行
{
    int Num = Images.size();//得到Vector容器中图片个数
    //设定包含这些图片的窗口大小，这里都是BGR3通道，如果做灰度单通道，稍微改一下下面这行代码就可以
    Mat Window(300 * ((Num - 1) / imgRows + 1), 300 * imgRows, CV_8UC3, Scalar(0, 0, 0));

    Mat Std_Image;//存放标准大小的图片
    Mat imageROI;//图片放置区域
    Size Std_Size = Size(300, 300);//每个图片显示大小300*300
    int x_Begin = 0;
    int y_Begin = 0;
    for (int i = 0; i < Num; i++)
    {
        x_Begin = (i % imgRows)*Std_Size.width;//每张图片起始坐标
        y_Begin = (i / imgRows)*Std_Size.height;
        resize(Images[i], Std_Image, Std_Size, 0, 0, INTER_LINEAR);//将图像设为标准大小
        //将其贴在Window上
        imageROI = Window(Rect(x_Begin, y_Begin, Std_Size.width, Std_Size.height));
        Std_Image.copyTo(imageROI);
    }
    dst = Window;
}

int main()
{
    Mat src = imread("../../resource/image/image3_35.tif");
    Mat image1,image2, dst;
    blur(src, image1, Size(3,3));
    medianBlur(src, image2, 3);

    imageVector.push_back(src);
    imageVector.push_back(image1);
    imageVector.push_back(image2);

    multipleImage(imageVector, dst, 3);

    namedWindow("Median Blur");
    imshow("Median Blur", dst);

    waitKey(0);
    destroyAllWindows();
}

